package cn.wp.ewallet.upms.dao.impl;

import cn.wp.common.core.dao.SqlString;
import cn.wp.ewallet.common.extension.constant.EwalletConstant;
import cn.wp.ewallet.upms.dao.BsFuncMenuInfoDao;
import cn.wp.ewallet.upms.extension.constant.EwalletUpmsConstant;
import cn.wp.ewallet.upms.model.entity.BsFuncMenuInfoDo;
import org.springframework.stereotype.Repository;
import cn.wp.common.core.dao.JdbcSupportTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 功能菜单-数据访问层实现
 * Created by zhangyongli on 2019/12/25
 */
@Repository
public class BsFuncMenuInfoDaoImpl implements BsFuncMenuInfoDao {

    @Autowired
    private JdbcSupportTemplate jdbcSupportTemplate;

    @Override
    public List<BsFuncMenuInfoDo> selectBsFuncMenuInfoBySystemUserId(String systemUserId) {
        SqlString sqlString = SqlString.newInstance();
        sqlString.add("select fm.*");
        sqlString.add("from bs_func_menu_info fm, bs_priv_func_rel pr, bs_priv_grant_rel gr, system_user_role_rel rr, system_user_info su");
        sqlString.add("where su.sys_user_id = rr.sys_user_id");
        sqlString.add("    and rr.sys_role_id = gr.grant_obj_id");
        sqlString.add("    and gr.priv_id = pr.priv_id");
        sqlString.add("    and fm.menu_id = pr.priv_ref_id");
        sqlString.add("    and pr.`status` = ?");
        sqlString.add("    and pr.priv_ref_type = ?");
        sqlString.add("    and gr.`status` = ?");
        sqlString.add("    and gr.grant_obj_type = ?");
        sqlString.add("    and gr.oper_type = ?");
        sqlString.add("    and rr.`status` = ?");
        sqlString.add("    and su.sys_user_id = ?");
        sqlString.add("    and fm.status = ?");
        sqlString.add("group by fm.menu_id");

        return jdbcSupportTemplate.selectList(sqlString.build(),
                new Object[] {
                        EwalletConstant.STATUS,
                        EwalletConstant.STATUS,
                        EwalletConstant.STATUS,
                        EwalletUpmsConstant.GRANT_OBJ_TYPE_ROLE,
                        EwalletConstant.STATUS,
                        EwalletConstant.STATUS,
                        systemUserId,
                        EwalletConstant.STATUS
                },
                BsFuncMenuInfoDo.class);
    }

}